package com.shujia.dim

import com.shujia.util.SparkTool
import org.apache.spark.sql.{DataFrame, SparkSession}

object DimUsertagApp extends SparkTool {
  /**
    * 在子类中实现run方法，实现自定义的代码累哦及
    *
    * 在子类run方法的前面加上下面两行代码
    * import spark.implicits._
    * import org.apache.spark.sql.functions._
    *
    * @param spark spark的环境
    */
  override def run(spark: SparkSession): Unit = {
    import spark.implicits._

    /**
      * 读取ods层中用户画像表的数据，对手机号，姓名，身份证号
      *
      * mdn string comment '手机号大写MD5加密'
      * ,name string comment '姓名'
      * ,gender string comment '性别，1男2女'
      * ,age string comment '年龄'
      * ,id_number string comment '证件号码'
      * ,number_attr string comment '号码归属地'
      * ,trmnl_brand string comment '终端品牌'
      * ,trmnl_price string comment '终端价格'
      * ,packg string comment '套餐'
      * ,conpot string comment '消费潜力'
      * ,resi_grid_id string comment '常住地网格'
      * ,resi_county_id string comment '常住地区县'
      *
      */

    val usertagDF: DataFrame = spark.sql(s"select * from ods.ods_usertag_m where month_id=$month_id")


    val resultDF: DataFrame = usertagDF
      .select(
        hashMd5($"mdn") as "mdn",
        hashMd5($"name") as "name",
        $"gender",
        $"age",
        hashMd5($"id_number") as "id_number",
        $"number_attr",
        $"trmnl_brand",
        $"trmnl_price",
        $"packg",
        $"conpot",
        $"resi_grid_id",
        $"resi_county_id"
      )

    //保存数据

    saveDataAndAddPartitionWithMonth(
      resultDF,
      "/daas/motl/dim/dim_usertag_msk_m",
      "dim.dim_usertag_msk_m")


  }
}
